package Object.enumTest;

public enum Enum3 {
    Red("red",1), Blue("blue",2), Pink("pink", 3);

    private String name;
    private int key;

    private Enum3 (String name,int key) {
        this.name = name;
        this.key = key;
    }
    public static Enum3 getEnumKey (int key) {
        for (Enum3 t: Enum3.values()) {
            if(t.key == key) {
                return t;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(Enum3.getEnumKey(1));
    }
}

 enum TestEnum {
    INSTANCE;
    public TestEnum getInstance(){
        return INSTANCE;
    }
    public static void main(String[] args) {
        TestEnum singleton1=TestEnum.INSTANCE;
        TestEnum singleton2=TestEnum.INSTANCE;
        System.out.println("两个实例是否相同："+(singleton1==singleton2));
    }
}

